@echo off
echo Testing Git Tag Functionality
echo =============================

REM Create a test file to commit
echo Test content for tag testing > test_tag_file.txt

REM Add and commit the test file
git add test_tag_file.txt
git commit -m "Test commit for tag functionality"

if %errorlevel% neq 0 (
    echo Error: Failed to commit test file
    pause
    exit /b 1
)

REM Test creating a tag
echo Creating test tag v1.9.9...
git tag -a v1.9.9 -m "Test tag v1.9.9"

if %errorlevel% neq 0 (
    echo Error: Failed to create tag
    pause
    exit /b 1
)

echo Successfully created tag v1.9.9

REM Test pushing the tag
echo Pushing tag to remote...
git push origin v1.9.9

if %errorlevel% neq 0 (
    echo Warning: Failed to push tag normally
    echo Trying with force...
    git push origin v1.9.9 --force
    
    if %errorlevel% neq 0 (
        echo Error: Failed to push tag even with force
        echo This may be a permission or network issue
        pause
        exit /b 1
    )
)

echo Successfully pushed tag v1.9.9

REM Clean up - delete the test tag locally and remotely
echo Cleaning up test tag...
git tag -d v1.9.9
git push origin --delete v1.9.9

REM Delete the test file
del test_tag_file.txt

echo Tag functionality test completed successfully!
pause